package com.microservice.skeleton.upms.controller;

import com.microservice.skeleton.common.vo.Result;
import com.microservice.skeleton.upms.entity.RcMenu;
import com.microservice.skeleton.upms.entity.RcUser;
import com.microservice.skeleton.upms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Mr.Yangxiufeng
 * Date: 2018-06-13
 * Time: 10:27
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired

    private UserService userService;

    /**
     * 根据用户名称查找用户
     * @param username 用户名称
     * @value
     */
    @GetMapping("findByUsername/{username}")
    public Result<RcUser> findByUsername(@PathVariable("username") String username){
        RcUser user = userService.findByUsername(username);
        if (user == null){
            return Result.failure(100,"======");
        }
        return Result.ok().setData(user);
    }


    /**
     * 添加新用户
     * @param user 新用户
     * @return 返回结果
     * @deprecated
     */
    @PostMapping("add")
    public Result<RcUser> add(RcUser user){
        userService.add(user);
        return Result.ok().setData(user);
    }

    /**
     * 更新用户
     * @param user
     * @return
     */
    @PostMapping("update")
    public Result<RcUser> update(@RequestBody RcUser user){
        return Result.ok().setData(user);
    }

}
